package cn.song.controller;

import cn.song.dto.OrderDto;
import cn.song.enums.ResultEnum;
import cn.song.exceptions.SellException;
import cn.song.service.OrderService;
import cn.song.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private PayService payService;

    @GetMapping("create")
    public void create(@RequestParam("orderId") String orderId, @RequestParam("returnUrl") String returnUrl){
        OrderDto orderDTO = orderService.findOne(orderId);
        if (orderDTO == null) {
            throw new SellException(ResultEnum.ORDER_NOT_EXIST);
        }
        payService.create(orderDTO);
    }

}
